package com.qingluan.testsome;

import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.transition.Scene;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.transition.TransitionManager;


public class MainActivity extends Activity {
	private ViewGroup container;
	private TextView thisis;
	private Button bt2;
	private Scene current;
	private Scene another;
	private Transition mytransition;
	private Integer count;
    @SuppressLint("NewApi") @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scene1); // 注意这里不是用的默认布局文件而是我们写的第一个文件
        count = 0;
        Kitkat();
        RelativeLayout base = (RelativeLayout)findViewById(R.id.scene_base);
        if (count == 0){
	        bt2 =(Button)findViewById(R.id.press_me);
	        bt2.setOnClickListener(new OnClickListener(){
	        	public void onClick(View view){
	        		count = (count +1)%2;
	        		
	        		TransitionManager.go(another);
	        	}
	        });
        }else {
        	bt2 = (Button)base.findViewById(R.id.press_me);
        	bt2.setOnClickListener(new OnClickListener(){
        		@Override
        		public void onClick(View view){
        			count = (count +1)%2;
        			
        			another.enter();
        			Toast.makeText(getApplicationContext(), current.toString(), Toast.LENGTH_SHORT).show();
        			TransitionManager.go(current);
        		}
        	});
        }
    }

    
    @TargetApi(19) 
    public void Kitkat (){
    	
        container = (ViewGroup)findViewById(R.id.scene_base);
        current = Scene.getSceneForLayout(container, R.layout.scene1, this);
        another = Scene.getSceneForLayout(container, R.layout.scene2, this);
        
        current.enter();
       
        
    }
  
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
